function Tel() {
    var o_tel = document.getElementById('tel').value;
    var telRe = /^1\d{10}$/;
    if (!telRe.test(o_tel)) {
        em_tel.innerHTML = '请输入11位有效手机号码';
        return false;
    } else {
        em_tel.innerHTML = '';
        return true;
    }
}
function Password1() {
    var o_psw1 = document.getElementById('psw1').value;
    var psw1Re = /^\w{6,16}$/;
    if (!psw1Re.test(o_psw1)) {
        em_psw1.innerHTML = '6~16个字符，不能有空格';
        return false;
    } else {
        em_psw1.innerHTML = '';
        return true;
    }
}
function Password2() {
    var o_psw1 = document.getElementById('psw1').value;
    var o_psw2 = document.getElementById('psw2').value;
    if (o_psw2 !== o_psw1) {
        em_psw2.innerHTML = '两次输入的密码不一致';
        return false;
    } else {
        em_psw2.innerHTML = '';
        return true;
    }
}

function Registor() {
    this.oTel = document.getElementById("tel");
    this.opsw1 = document.getElementById("psw1");
    this.opsw2 = document.getElementById("psw2");
    this.ozc = document.getElementById("zc");
    this.arr = [false,false];
    this.addEvent();
}
Registor.prototype = {
    constructor: Registor,
    addEvent(){
        let that = this;
        this.ozc.onclick = function(){
            if(that.arr.indexOf(false) !== -1){
             alert('请完善注册信息！');
            }else{
             let tel = that.oTel.value;
             //获取密码
             let psw2 = opsw2.value;
             let $ = new Tool();
             /*
              *  '{张三:123,李四:456}'
              */
             //获取现有的cookie
             let cookie_str = $.getCookie('registors') ? $.getCookie('registors') : '';
            //  alert(cookie_str);
             //转为对象
             let cookie_obj = $.convertStrToObj(cookie_str);
             //in : 判断key是否属于某个对象，返回布尔值
             //判断当前用户是否存在
             if (tel in cookie_obj) {
                 alert('用户名已存在！');
                 return;
             } else {
                 //添加到对象中
                 cookie_obj[tel] = psw2;
             }
             //创建cookie
             $.cookie('registors',JSON.stringify(cookie_obj),{expires : 9,path : '/'});
             alert('注册成功！');
             // otel.value = '';
             // opsw1.value = '';
             // opsw2.value = '';
            
        }
    }

}

new Registor();
   


   
			
			
			

